package com.wksc.framework.impexp.reader;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import jxl.read.biff.BiffException;

/**
 * <p>
 * Title(文件名): ${file_name}
 * </p>
 * <p>
 * Description(描述): ${todo}
 * </p>
 * <p>
 * Copyright(版权): Copyright (c) ${year}
 * </p>
 * <p>
 * Company(公司): 成都四方信息技术有限公司
 * </p>
 * <p>
 * CreateTime(生成日期)：11-11-13下午4:23
 * </p>
 * 
 * @author wanglei
 * @version ${project_name}
 */
public class CsvReader extends Reader {

	private List<String> dataList = new ArrayList<String>(5000);

	protected CsvReader() {
		super();
	}

	@Override
	public int countTotalLine() {
		return dataList.size();
	}

	@Override
	public String[] readByRow(int lineNum) {
		String lineContent = dataList.get(lineNum);
		// 以逗号分隔将字符串转换为字符串数组
		return lineContent.split("/t", -1);
	}

	@Override
	public void close() {

	}

	@Override
	protected void initFile() throws BiffException, IOException {
		InputStream inputStream = new FileInputStream(this.file);
		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		String line = null;
		while ((line = bufferedReader.readLine()) != null) {
			dataList.add(line);
		}
		bufferedReader.close();
		inputStreamReader.close();
		inputStream.close();
	}

}
